<template>
	<view class="list">
		<view class="header">
			推荐商品
		</view>
		<view class="product-item" v-for="item in list" :key="item.productId" @click="toDetail(item.productId)">
			{{item.productName}}
		</view>
	</view>
</template>

<script>
	import {listApi} from "@/api/index.js"
	export default {
		data() {
			return {
				list: [],
				count: 3,
				page: 1
			}
		},
		mounted() {
			this.getData()
		},
		methods: {
			async getData() {
				const res = await listApi({count: this.count, page: this.page});
				this.list = [...this.list, ...res.result.list];
				this.page++;
			},
			toDetail(id) {
				uni.navigateTo({
					url: '../../packagea/detail/detail?id=' + id
				});
			}
		}
	}
</script>

<style scoped>
	.header {
		width: 100%;
		height: 50rpx;
		line-height: 50rpx;
		vertical-align: middle;
	}
	.header::before {
		content: "";
		display: inline-block;
		width: 10rpx;
		height: 40rpx;
		background-color: lightcoral;
		vertical-align: middle;
		margin: 0 10rpx;
	}
	
	.product-item {
		height: 120rpx;
		border-bottom: 1rpx solid #ccc;
	}
</style>